有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Maven导入问题,在complie时间使用里程碑版本,但在运行时使用最新版本

我已经在RC文件中声明了依赖项的POM.xm版本。在编译时使用RC版本,但在运行时使用RELEASE版本,这会导致java.lang.NoSuchMethodError

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-elasticsearch</artifactId>
    <version>4.1.0-RC1</version>
</dependency>

这会将4.1.0-RC14.0.3.RELEASE添加到类路径中

SearchHit#getIndex4.1.x版本中引入,该版本仍处于里程碑阶段。以下是这个maven模块的完整pom.xml(删除了其他依赖项):

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>
  
  <parent>
    <artifactId>example-parent</artifactId>
    <groupId>com.example</groupId>
    <version>1.0-SNAPSHOT</version>
  </parent>

  <artifactId>search</artifactId>

  <dependencies>
    <dependency>
      <groupId>org.springframework.data</groupId>
      <artifactId>spring-data-elasticsearch</artifactId>
      <version>4.1.0-RC1</version>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
      </plugin>
    </plugins>
  </build>

  <repositories>
    <repository>
      <id>spring-libs-snapshot</id>
      <name>Spring Snapshot Repository</name>
      <url>https://repo.spring.io/libs-milestone</url>
    </repository>
  </repositories>

</project>

这是一个多模块spring boot项目,使用spring-boot-starter-parent版本2.3.3.RELEASE
问题出在哪里?我正在使用Intellij IDEA

更新:

  1. 如果我从这个“搜索”模块中删除spring-data-elasticsearch,两个版本都会从项目中删除
  2. 我正在使用这个“搜索”模块进入“休息”模块。我运行了mvn dependency:tree,结果的日志令人惊讶。“search”模块有4.1.0-RC1版本,但在“rest”模块中,“search”被导入,并且没有额外的elasticsearh依赖性出现4.0.3.RELEASE

从“搜索”模块: search module has RC version

从我使用“搜索”依赖项的“rest”模块 rest module brining RELEASE version

这个依赖项负责添加两个版本。删除它会同时删除这两个依赖项。奇怪的 enter image description here


共 (0) 个答案